<div class="row">
	<div class="col-sm-12">
		<div>
    		<a href="/admin/nursery/add?per_page=<?php if(!empty($_REQUEST['per_page']))echo $_REQUEST['per_page']?>" class="btn btn-info_01 float_right btn_search">添加</a>
    	</div>
		<div class="space"></div>
		<table width="100%" class="table table-striped table-bordered table-hover">
			<tr>
			    <th height="30">ID</th>
				<th height="30">名称</th>
				<th height="30">地区</th>
				<th height="30">市区</th>
				<th height="30">地址</th>
				<th height="30">说明</th>
				<th>客服电话</th>
				<th height="30">登陆</th>
				<th>划课</th>
				<th height="30">权重</th>
				<th height="30">操作</th>
			</tr>
			<?php if(!empty($nursery_list)){foreach ($nursery_list as $key=>$val){?>
			<tr>
			  <td height="30"><?php echo $val['id']?></td>
			  <td height="30"><?php echo $val['title'];?></td>
			  <td height="30"><?php echo $val['area_title'];?></td>
			  <td height="30"><?php echo $val['city_title'];?></td>
			  <td height="30"><?php echo $val['address'];?></td>
			  <td height="30"><?php echo $val['explain']?></td>
			  <td><?php echo $val['telephone']?></td>
			  <td height="30">
			  <!-- 登录 -->
			  <input type="hidden" name="login_<?php echo $val['id']?>" value="<?php echo $val['is_allow_login'];?>"/>
			  <select onchange="updatelogin(this,1)" id='<?php echo $val['id']?>'>
			  	<option value="1" <?php if($val['is_allow_login'] == 1)echo 'selected'?>>允许</option>
			  	<option value="0" <?php if($val['is_allow_login'] == 0)echo 'selected'?>>不允许</option>
			  </select>
			  </td>
			  <td>
			  <!-- 划课 -->
			  <input type="hidden" name="huake_<?php echo $val['id']?>" value="<?php echo $val['is_allow_huake'];?>"/>
			  <select onchange="updatelogin(this,2)" id='<?php echo $val['id']?>'>
			  	<option value="1" <?php if($val['is_allow_huake'] == 1)echo 'selected'?>>允许</option>
			  	<option value="0" <?php if($val['is_allow_huake'] == 0)echo 'selected'?>>不允许</option>
			  </select>			  
			  </td>
			  <td height="30">
			  <input type="text" name="weight" id="<?php echo $val['id'];?>" onchange="sort(this);" value="<?php echo $val['weight'];?>" style="width:50px">
			  </td>
			  <td height="30">
			  <a href='/admin/nursery/update?id=<?php echo $val['id']?>&per_page=<?php if(!empty($_REQUEST['per_page']))echo $_REQUEST['per_page']?>'>修改</a>
			   | <a href='/admin/nursery/delete?id=<?php echo $val['id']?>&status=1' onclick="if(confirm('确定要删除吗？')){return true;}else{return false;};">删除</a>	      
			   </td>
		  </tr>
		  <?php }}else{?>
			<tr>
			  <td height="30" colspan="9"><div align="center"><?php echo $error;?></div></td>
		  </tr>
		  <?php }?>
	  </table>
		
		<div class="float_right">
			<?php echo $pagelink;?>
		</div>
	</div>
</div>
<script type="text/javascript">
/**
 * 排序
 */
function sort(obj){
	var id = $(obj).attr('id');
	var sort = $(obj).val();
	$.ajax({
	    type : "get", 
	    async:false, 
	    url : "/admin/nursery/sort?id="+id+'&sort='+sort, 
	    dataType : "json", 
	    success : function(data){
		    alert(data['msg']);
	    }, 
	    error:function(){
	        alert('fail'); 
	    } 
	});
}
/**
 * 修改
 * type=1登录，type=2划课
 */
function updatelogin(object,type){
	var id = $(object).attr('id');
	var status = $(object).val();
	if(type==1){
		var original = $("[name='login_"+id+"']").val();
	}else{
		var original = $("[name='huake_"+id+"']").val();
	}
	if(confirm('确定要修改吗？')){
	    $.ajax({
           type: 'get',
           url: '/admin/nursery/updatelogin?id='+id+'&status='+status+'&type='+type,
           async : false,
           dataType: 'json',
           success: function (d){
    	        if(d['code'] != 10){
    	        	$(object).val(original);
        	    }
    	        alert(d['msg']);
           },
    	});
	}else{
		$(object).val(original);
	}
}
</script>
<!--content-->